/*
 * Copyrights of MYeBills. Do not copy or distribute without permissions.
 *
 * TODO
 */
package com.mbbmap.app.dao;


import java.util.Date;
/**
 * @author Lue
 *
 * Payee User data structure
 */
public class UserDao implements Comparable {

    public static final String PROP_EMAIL = "email";
    public static final String PROP_HANDPHONE_NO = "handPhoneNo";

    String userLogin, loginPassword, userName,  agencyCode, agencyName, userRole,
    	handPhoneNo, email, remark, roleName, blockAccessDate, createStatus,countryCode;
    String fullName, userDept, userRegion;
    public long DBId= -1;
    boolean locked = false;
    String userEnabled = "";

    //security info
    Date lastLoginTimestamp, createdTimestamp, lastUpdatedTimestamp, lastPwdChanged;
    String strlastLoginTimestamp, strcreatedTimestamp, strlastUpdatedTimestamp, strlastPwdChanged;
    String lastLoginIP, createdBy, lastUpdatedBy, resetPwdFlag, lockedFlag;
    boolean isAllowedAccess = false;
    String  strAccessReason = "";
    int noBadPwdAttempts = -1;


    public int compareTo(Object obj) throws ClassCastException {

        if (!(obj instanceof UserDao))
            throw new ClassCastException("UserDao object expected.");

        UserDao user = (UserDao) obj;
        int roleComp = userRole.compareTo(user.getUserRole());

        return ((roleComp == 0) ? userLogin.compareTo(user.getUserLogin()) : roleComp);
      }

      public boolean equals(Object obj) {
        if (!(obj instanceof UserDao)) {
          return false;
        }
        UserDao user = (UserDao) obj;
        return userRole.equals(user.getUserRole()) && userLogin.equals(user.getUserLogin());
      }

    public UserDao (String login, String password, String name,  String agencyCode, String role, String hpNo, String email,
            String enabled, String createStatus, String remark, String dateNoAccess) {
        this.userLogin = login;
        this.loginPassword = password;
        this.userName = name;
        this.agencyCode = agencyCode;
        this.userRole = role;
        this.handPhoneNo = hpNo;
        this.email = email;
        this.userEnabled = enabled;
        this.remark = remark;
        this.blockAccessDate = dateNoAccess;
        this.createStatus = createStatus;
    }

    public UserDao() {

    }

    public void setUserLogin (String login) {
        userLogin = login;
    }

    public void setUserDBId (long id) {
        DBId = id;
    }

    public void setLoginPassword (String loginPass) {
        loginPassword = loginPass;
    }

    public void setUserName (String name) {
        userName = name;
    }

    public void setAgencyCode (String agCode) {
        agencyCode = agCode;
    }

    public void setAgencyName (String agName) {
        agencyName = agName;
    }

    public void setUserRole (String role) {
        userRole = role;
    }

    public void setRoleName (String rolename) {
        roleName = rolename;
    }

    public void setHandPhoneNo (String hpNo) {
        handPhoneNo = hpNo;
    }

    public void setEmail (String email) {
        this.email = email;
    }

    public void setUserEnabled (String enabled) {
        this.userEnabled = enabled;
    }

    public void setRemark (String rem) {
        this.remark = rem;
    }

    public void setUserLocked (boolean locked) {
        this.locked = locked;
    }

    public void setCreateStatus (String status) {
        this.createStatus = status;
    }

    public void setLastLoginTimestamp (Date date) {
        this.lastLoginTimestamp = date;
    }

    public void setCreatedTimestamp (Date date) {
        this.createdTimestamp = date;
    }

    public void setLastUpdatedTimestamp (Date date) {
        this.lastUpdatedTimestamp = date;
    }

    public void setLastPwdChanged (Date date) {
        this.lastPwdChanged = date;
    }

    public void setLastUpdatedBy (String updatedBy) {
        this.lastUpdatedBy = updatedBy;
    }

    public void setCreatedBy (String createdBy) {
        this.createdBy = createdBy;
    }

    public void setLastLoginIp (String ipHost) {
        this.lastLoginIP = ipHost;
    }

    public void setResetPwdFlag (String pwdFlag) {
        this.resetPwdFlag = pwdFlag;
    }

    public void setNoBadPwdAttempts (int no) {
        this.noBadPwdAttempts = no;
    }

    public void setLockedFlag(String flag) {
        this.lockedFlag = flag;
    }

    public void setBlockAccessDate(String date) {
        this.blockAccessDate = date;
    }
    
    public void setFullName (String fullName) {
        this.fullName = fullName;
    }
    
    public void setUserDept (String userDept) {
        this.userDept = userDept;
    }
    
    public void setUserRegion (String userRegion) {
        this.userRegion = userRegion;
    }

    // GETTER

    public String getUserLogin() {
        return emptyStr(userLogin);
    }

    public long getUserDBId() {
        return DBId;
    }

    public String getLoginPassword() {
        return emptyStr(loginPassword);
    }

    public String getUserName () {
        return emptyStr(userName);
    }

    public String getAgencyCode () {
        return emptyStr(agencyCode);
    }

    public String getAgencyName () {
        return emptyStr(agencyName);
    }

    public String getUserRole () {
        return emptyStr(userRole);
    }

    public String getRoleName () {
        return emptyStr(roleName);
    }

    public String getHandPhoneNo () {
        return emptyStr(handPhoneNo);
    }

    public String getEmail () {
        return emptyStr(email);
    }

    public String getRemark () {
        return emptyStr(remark);
    }

    public String getUserEnabled () {
        return userEnabled;
    }

    public boolean getUserLocked () {
        return locked;
    }

    public String getCreateStatus () {
        return createStatus;
    }

    public String getLockedFlag() {
        return emptyStr(lockedFlag);
    }

    public Date getLastLoginTimestamp () {
        return lastLoginTimestamp;
    }

    public Date getCreatedTimestamp () {
        return createdTimestamp;
    }

    public Date getLastUpdatedTimestamp () {
        return lastUpdatedTimestamp;
    }

    public Date getLastPwdChanged () {
        return lastPwdChanged;
    }

    public String getLastLoginIP () {
        return emptyStr(lastLoginIP);
    }

    public String getLastUpdatedBy () {
        return emptyStr(lastUpdatedBy);
    }

    public String getCreatedBy () {
        return emptyStr(createdBy);
    }

    public String getResetPwdFlag () {
        return emptyStr(resetPwdFlag);
    }

    public String getBlockAccessDate () {
        return emptyStr(blockAccessDate);
    }

    public int getNoBadPwdAttempts () {
        return noBadPwdAttempts;
    }
    
    public String getFullName() {
        return emptyStr(fullName);
    }
    
    public String getUserDept() {
        return emptyStr(userDept);
    }
    
    public String getUserRegion() {
        return emptyStr(userRegion);
    }

    // Added by Meau 20091129
    public String getCountryCode() {
        return countryCode;
    }

    public void setCountryCode(String countryCode) {
        this.countryCode = countryCode;
    }

    // end added by Meau 20091129

    // Added by MKang 20101023
    public boolean getIsAccessAllow() {
        return isAllowedAccess;
    }

    public void setIsAccessAllow(boolean isAllowedAccess) {
        this.isAllowedAccess = isAllowedAccess;
    }

    public String getAccessReason() {
        return strAccessReason;
    }

    public void setAccessReason(String strAccessReason) {
        this.strAccessReason = strAccessReason;
    }
    // end added by Meau 20091129
 
   //////////////////////////////////////////////////////////////////
    public String toString(){
        StringBuffer tmp = new StringBuffer();
        tmp.append("Login["+getUserLogin() + "],");
        //tmp.append("DBId["+getUserDBId() + "],");
        //tmp.append("Password["+getLoginPassword() + "],");
        tmp.append("Name["+getUserName() + "],");
        tmp.append("Role ID["+getUserRole() + "],");
        tmp.append("Agency Code["+getAgencyCode() + "],");
        tmp.append("Hand Phone["+getHandPhoneNo () + "],");
        tmp.append("Email["+getEmail () + "],");
        tmp.append("Create Status["+getCreateStatus () + "],");
        tmp.append("Enabled["+getUserEnabled () + "],");
        tmp.append("Locked["+getUserLocked () + "],");
        tmp.append("Remark["+getRemark () + "],");
        tmp.append("BlockAccessDate["+getBlockAccessDate () + "],");
        //tmp.append("\n");
        //tmp.append("LastLoginTimestamp["+getLastLoginTimestamp () + "],");
        //tmp.append("CreatedTimestamp["+getCreatedTimestamp () + "],");
        //tmp.append("LastUpdatedTimestamp["+getLastUpdatedTimestamp () + "],");
        //tmp.append("LastPwdChanged["+getLastPwdChanged () + "],");
        //tmp.append("LastLoginIP["+getLastLoginIP () + "],");
        //tmp.append("LastUpdatedBy["+getLastUpdatedBy () + "],");
        //tmp.append("ResetPwdFlag["+getResetPwdFlag () + "],");
        //tmp.append("NoBadPwdAttempts["+getNoBadPwdAttempts () + "],");

        return tmp.toString();
    }

    private String emptyStr (String input) {
        if (input == null)
            return "";
        else
            return input.trim();
    }

	public String getStrlastLoginTimestamp() {
		return strlastLoginTimestamp;
	}

	public void setStrlastLoginTimestamp(String strlastLoginTimestamp) {
		this.strlastLoginTimestamp = strlastLoginTimestamp;
	}

	public String getStrcreatedTimestamp() {
		return strcreatedTimestamp;
	}

	public void setStrcreatedTimestamp(String strcreatedTimestamp) {
		this.strcreatedTimestamp = strcreatedTimestamp;
	}

	public String getStrlastUpdatedTimestamp() {
		return strlastUpdatedTimestamp;
	}

	public void setStrlastUpdatedTimestamp(String strlastUpdatedTimestamp) {
		this.strlastUpdatedTimestamp = strlastUpdatedTimestamp;
	}

	public String getStrlastPwdChanged() {
		return strlastPwdChanged;
	}

	public void setStrlastPwdChanged(String strlastPwdChanged) {
		this.strlastPwdChanged = strlastPwdChanged;
	}

}
